package fy.test.hr;

import java.util.HashMap;
import java.util.Map;

import com.seeyon.client.CTPRestClient;
import com.seeyon.client.CTPServiceClientManager;
import com.seeyon.ctp.organization.OrgConstants;
import com.seeyon.ctp.organization.bo.MemberPost;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import net.sf.json.JSONObject;

public class ZzcOrgManager {

    public static void main(String[] args) {
        // 指定协议、IP和端口，获取ClientManager
        CTPServiceClientManager clientManager = CTPServiceClientManager.getInstance("http://10.111.0.54:80");

        // 取得REST动态客户机实例
        CTPRestClient client = clientManager.getRestClient();
        client.authenticate("fy_form_reader", "form_reader2015");
        String[] s = {"test.zheng"};
        for (int i = 0; i < s.length; i++) {

            try {
                String result = client.get("orgMember/?loginName=" + s[i], String.class);
                JSONObject jo = new JSONObject().fromObject(result);

//				long accountID = (Long) jo.get("orgAccountId");
                long id = (Long) jo.get("id");

                System.out.println(result);
                LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
                map.put("id", id);
//                map.put("orgAccountId", 1690589518483638343l);
//                map.put("orgPostId", null);
//                map.put("orgLevelId", null);
//                map.put("orgDepartmentId", null);

//                LinkedHashMap<String, Object> second_post = new LinkedHashMap<String, Object>();
//                second_post.put("postId", 8524691702057484944L);
//                second_post.put("depId", 2730157404181317866L);
//                second_post.put("memberId", -1825607432309486470L);
//                second_post.put("type", "Second");
//                second_post.put("orgAccountId", 5686590792835548528l);
                MemberPost secondpost = new MemberPost();
                secondpost.setMemberId( -1825607432309486470L);
                secondpost.setType(OrgConstants.MemberPostType.Second);
                secondpost.setDepId(2730157404181317866L);
                secondpost.setOrgAccountId(5686590792835548528l);
                secondpost.setPostId(8524691702057484944L);
                        

                List<MemberPost> list = new ArrayList();
                list.add(secondpost);
                map.put("second_post", list);

                client.put("orgMember", map, String.class);

//{
//    "memberId" : -1825607432309486470,
//    "depId" : 2730157404181317866,
//    "postId" : 8524691702057484944,
//    "levelId" : null,
//    "dutyLevelId" : null,
//    "orgAccountId" : 5686590792835548528,
//    "code" : null,
//    "sortId" : 1125,
//    "type" : "Second",
//    "conRoles" : ""
//  }, {
//    "memberId" : -1825607432309486470,
//    "depId" : 4594242975542103074,
//    "postId" : -7939833493338503150,
//    "levelId" : null,
//    "dutyLevelId" : null,
//    "orgAccountId" : 5686590792835548528,
//    "code" : null,
//    "sortId" : 1125,
//    "type" : "Second",
//    "conRoles" : ""
//  }
            } catch (Exception e) {
                System.out.println(s[i]);
            }
        }

    }
}
